// pages/jifen_shangcheng/jifen_shangcheng.js
var util = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 500,
    movies: [
      { url: '../../images/new/7.jpg' },
      { url: '../../images/new/3.png' },
    ],
    nav:[{},{},{},{},{}],
    goods: [
      {url:'../../images/new/1.png',name:'xxxxxx',price:12,oldprice:120,sale:1},
      { url: '../../images/new/3.png', name: 'xxxxxx', price: 12, oldprice: 120, sale: 1,id:1},
      { url: '../../images/new/4.jpg', name: 'xxxxxx', price: 12, oldprice: 120, sale: 1, id: 2 },
      { url: '../../images/new/5.jpg', name: 'xxxxxx', price: 12, oldprice: 120, sale: 1, id: 3},
      { url: '../../images/new/6.jpg', name: 'xxxxxx', price: 12, oldprice: 120, sale: 1, id: 4},
      { url: '../../images/new/7.jpg', name: 'xxxxxx', price: 12, oldprice: 120, sale: 1, id: 5 },
      { url: '../../images/new/8.jpg', name: 'xxxxxx', price: 12, oldprice: 120, sale: 1, id: 6 },
      { url: '../../images/new/9.jpg', name: 'xxxxxx', price: 12, oldprice: 120, sale: 1, id: 7},
      { url: '../../images/new/10.jpg', name: 'xxxxxx', price: 12, oldprice: 120, sale: 1, id:8},
      { url: '../../images/new/11.jpg', name: 'xxxxxx', price: 12, oldprice: 120, sale: 1, id:9}
    ],
    currentPage: 1,
    totalPage: 1,
  },
  clickurl:function(e){
    var id = e.currentTarget.dataset.id;
    console.log(id)
    wx.navigateTo({
      url: '../goodsDetails/goodsDetails?id=' + id,
    })
  },
  myPoint:function(){
    wx.navigateTo({
      url: '../point_detail/detail',
    })
    
  },
  //积分商城
  orderJi(){
    wx.navigateTo({
      url: '../jifen_order/jifen_order',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.banner();
    // this.goodsList();
  },
  banner:function(){
    var that = this;
    util.commonRequest('banner', 'post', {}, function (res) {
     if(res.data.code == 200 ){
       that.setData({
         movies:res.data.data
       })
     }
    });
  },
  goodsList:function(){
    var that = this;
    util.commonRequest('goodList', 'post', { currentPage: that.data.currentPage}, function (res) {
      var data = res.data;
      if (data.code == 200) {
        var tempArr = data.data.data;
        var oriArr = that.data.goods;
        var finalyArr = oriArr.concat(tempArr);
        that.setData({
          goods: finalyArr,
          totalPage: data.data.last_page
        })
      }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },
  
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
 
    var currentpage = this.data.currentPage;
    var totalpage = this.data.totalPage;
    if (currentpage < totalpage) {
      this.setData({
        currentPage: currentpage + 1
      })
      this.goodsList();
    } else {
      wx.showToast({
        title: '没有更多了',
        icon: 'none'
      })
      console.log("已经是全部数据");
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})